<template>
  <div v-loading="isLoading" class="login-container">
    <el-form
      ref="from"
      :model="from"
      status-icon
      :rules="rules"
      class="demo-from"
    >
      <div class="title-container">
        <h3 class="title">
          <img src="../../assets/common/login-logo.png" alt="">
        </h3>
      </div>
      <el-form-item prop="mobile">
        <el-input
          v-model="from.mobile"
          prefix-icon="el-icon-user-solid"
          type="text"
          autocomplete="off"
        />
      </el-form-item>
      <el-form-item prop="password">
        <el-input
          v-model="from.password"
          prefix-icon="el-icon-lock"
          type="password"
          autocomplete="off"
          show-password
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          class="login-btn"
          @click="loginBtn"
        >登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
/* eslint-disable */
// import { loginApi } from '../../api/user'
import { validatePassword, validateMobile } from '@/utils/validate'
export default {
  data() {
    return {
      isLoading: false,
      from: {
        mobile: '13800000002',
        password: '123456'
      },
      rules: {
        mobile: [
          { required: true, message: '请输入手机号', trigger: 'blur' },
          {
            validator: validateMobile,
            message: '输入正确的手机号',
            trigger: 'blur'
          }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          {
            validator: validatePassword,
            message: '输入正确的手机号',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  methods: {
    loginBtn() {
      this.$refs.from.validate(async result => {
        try {
          this.isLoading = true

          await this.$store.dispatch('user/login', {
            mobile: this.from.mobile,
            password: this.from.password
          })
          this.$router.push('/dashboard')
        } catch (error) {
          console.log(error)
          console.log('登录失败')
        } finally {
          this.isLoading = false
        }
        // if (result) {
        //   // console.log('ok')
        //   const res = await loginApi({
        //     mobile: this.from.mobile,
        //     password: this.from.password
        //   })
        //   console.log(res)
        // } else {
        //   console.log('error submit!!')
        //   return false
        // }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.login-container {
  height: 100%;
  background-image: url('~@/assets/common/login.jpg'); // 设置背景图片
  background-position: center; // 将图片位置设置为充满整个屏幕
  display: flex;
  justify-content: center;
  align-items: center;
  .demo-from {
    width: 400px;
  }
  // .el-input,
  // .el-input--prefi,
  // .el-form-item__content,
  ::v-deep input.el-input__inner {
    background-color: #d2e4ff;
    padding-top: 25px;
    padding-bottom: 25px;
  }
  .title-container {
    margin-bottom: 50px;
    img {
      width: 100%;
    }
  }
  .login-btn {
    width: 100%;
    // padding: 25px 0;
    background: #407ffe;
    height: 64px;
    line-height: 32px;
    font-size: 24px;
    border-width: 0;
  }
}
</style>
